package lifei.lifei.mybatis.jdbcdemo;


import java.sql.*;

public class LinkTabSelect {
    public static void main(String[] args) throws ClassNotFoundException, SQLException {
//注册驱动
        Class.forName("com.mysql.cj.jdbc.Driver");
        //获取连接
        Connection conn = DriverManager.getConnection(
                "jdbc:mysql:///jtsys?serverTimezone=GMT",
                "root",
                "root");
        System.out.println(conn);
        //定义SQL
        String sql = "select * from sys_logs";
        //创建传输器对象
        PreparedStatement ps = conn.prepareStatement(sql);
        //执行SQL
        ResultSet rs = ps.executeQuery();
        //处理结果集
        while (rs.next()){
            int id = rs.getInt("id");
            String username = rs.getString("username");
            String operation = rs.getString("operation");
            String method = rs.getString("method");
            String params = rs.getString(5);
            long time = rs.getInt(6);
            String ip = rs.getString(7);
            Date createdTime = rs.getDate(8);
            System.out.println(id+" "+username+" "+operation+" "+method+" "+params+" "+
                    time+" "+ip+" "+createdTime);

        }
        //释放资源
        ps.close();
        conn.close();
        rs.close();

    }

}
